package com.example.myapplication11_1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.SpannableString;
import android.view.View;
import android.widget.Button;
import android.view.LayoutInflater;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btnDialog = findViewById(R.id.btn_dialog);
        btnDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                SpannableString title = new SpannableString("普通对话框");
                title.setSpan(new android.text.style.ForegroundColorSpan(android.graphics.Color.parseColor("#46bbe6")), 0, title.length(), android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                builder.setTitle(title);
                builder.setIcon(R.drawable.icon8);
                builder.setMessage("无法进行此操作");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.show();
            }
        });
    }
}